package com.wenjh.jdmzt.android.synctask;

import java.util.ArrayList;
import java.util.List;


public abstract class CallbackTask<T> implements Runnable {
	protected List<Callback<T>> callbacks = null;
	boolean finish = false;
	
	public CallbackTask(Callback<T> callback) {
		this();
		addCallback(callback);
	}
	
	public CallbackTask() {
		callbacks = new ArrayList<Callback<T>>();
	}
	
	@Override
	public abstract void run();
	
	public void addCallback(Callback<T> callback) {
		callbacks.add(callback);
	}
	
	
	protected void callBack(T t) {
		finish = true;
		for (Callback<T> callback : callbacks) {
			callback.afterRun(t);
		}
	}
	
	public boolean isFinish() {
		return finish;
	}
}
